import React, { Component } from 'react'

import './Footer.css'
export default class Footer extends Component {
  render() {
    // 动态计算当前任务总数和完成任务总数
    const allTotal = this.props.todos.length
    const doneTotal = this.props.todos.filter((item) => item.isDone).length
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={allTotal === doneTotal}
            onChange={(e) => {
              // 将全局按钮的目标值,传递给App组件,
              this.props.allCheck(e.target.checked)
            }}
          />
        </label>
        <span>
          <span>已完成 {doneTotal}</span> / 全部 {allTotal}
        </span>
        <button
          className="btn btn-danger"
          onClick={() => {
            this.props.clearAllDone()
          }}
        >
          清除已完成任务
        </button>
      </div>
    )
  }
}
